// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import java.sql.SQLException;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.core.znet.SteamUtils;
import zombie.network.GameServer;
import zombie.network.ServerWorldDatabase;

@CommandName(
    name = "unbanuser"
)
@CommandArgs(
    required = {"(.+)"}
)
@CommandHelp(
    helpText = "UI_ServerOptionDesc_UnBanUser"
)
@RequiredRight(
    requiredRights = 48
)
public class UnbanUserCommand extends CommandBase {
    public UnbanUserCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() throws SQLException {
        String string0 = this.getCommandArg(Integer.valueOf(0));
        String string1 = ServerWorldDatabase.instance.banUser(string0, false);
        LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " unbanned user " + string0);
        if (!SteamUtils.isSteamModeEnabled()) {
            ServerWorldDatabase.instance.banIp(null, string0, null, false);

            for (int _int = 0; _int < GameServer.udpEngine.connections.size(); _int++) {
                UdpConnection udpConnection = (UdpConnection)GameServer.udpEngine.connections.get(_int);
                if (udpConnection.username.equals(string0)) {
                    ServerWorldDatabase.instance.banIp(udpConnection.ip, string0, null, false);
                    break;
                }
            }
        }

        return string1;
    }
}
